3 Problem: 11110 - Equidivisions
17 int g
[MAXN
+1][MAXN
+1];
18 bool v
[MAXN
+1][MAXN
+1];
20 //Retorna el número de casillas visitadas empezando en la casilla (i,j) si es de color c.
21 int dfs(int i
, int j
, int c
){
22 if ( (0 <= i
&& i
< n
&& 0 <= j
&& j
< n
&&
23 !v
[i
][j
] && c
== g
[i
][j
]) == false )
27 for (int di
=-1; di
<=1; ++di
){
28 for (int dj
=-1; dj
<=1; ++dj
){
29 if ((di
== 0 || dj
== 0) && (di
!= 0 || dj
!= 0) ){
30 ans
+= dfs(i
+di
, j
+dj
, c
);
38 for (int color
=0; color
<n
; ++color
){
39 for (int i
=0; i
<n
; ++i
){
40 for (int j
=0; j
<n
; ++j
){
41 if (g
[i
][j
] == color
&& !v
[i
][j
]){
42 if (dfs(i
, j
, color
) != n
) return false;
51 while (cin
>> n
&& n
){
54 memset(g
, 0, sizeof g
);
55 memset(v
, 0, sizeof v
);
56 for (int i
=1; i
<n
; ++i
){
57 //Leer la partición de color i.
58 //La partición que no está indicada es de color 0.
61 stringstream
sin(line
);
63 while (sin
>> r
>> c
) g
[--r
][--c
] = i
;
66 cout
<< (todo_bien() ? "good" : "wrong") << endl
;